using System.Linq;
using System.Numerics;
using NUnit.Framework;
using ProjectEuler.Core.Helpers;

namespace ProjectEuler.Core
{
    public class Problem55 : IProjectEulerProblem
    {
        protected bool IsLychrel(BigInteger n)
        {
            for(int i=0;i<50;i++)
            {
                var reverseN = BigInteger.Parse(n.ToString().Reverse());
                n += reverseN;
                if (n.ToString().IsPalindrome())
                {
                    return false;
                }
            }
            return true;
        }

        public int Number
        {
            get { return 55; }
        }

        public string Description
        {
            get { return "How many Lychrel numbers are there below ten-thousand?"; }
        }

        public string Answer
        {
            get
            {
                return Enumerable.Range(10, 9999).Where(n => IsLychrel(n)).Count().ToString();
            }
        }
    }

    [TestFixture]
    public class Problem55Tests : Problem55
    {
        [Test]
        public void Then_47_is_not_Lychrel()
        {
            Assert.AreEqual(false, IsLychrel(47));
        }

        [Test]
        public void Then_349_is_not_Lychrel()
        {
            Assert.AreEqual(false, IsLychrel(349));
        }

        [Test]
        public void Then_10677_is_Lychrel_for_less_than_50_iterations()
        {
            Assert.AreEqual(true, IsLychrel(10677));
        }

        [Test]
        public void Then_4994_is_Lychrel_for_less_than_50_iterations()
        {
            Assert.AreEqual(true, IsLychrel(4994));
        }
    }
}